<template>
  <div v-if="showNotification" class="notification-overlay">
    <div class="notification-card">
      <div class="notification-header">
        <span class="notification-icon">🎉</span>
        <h3>任务完成通知</h3>
        <button @click="closeNotification" class="close-btn">×</button>
      </div>
      <div class="notification-content">
        <p><strong>任务ID:</strong> {{ notification.taskId }}</p>
        <p><strong>状态:</strong> 
          <span :class="['status-badge', `status-${notification.status.toLowerCase()}`]">
            {{ getStatusText(notification.status) }}
          </span>
        </p>
        <p v-if="notification.message"><strong>消息:</strong> {{ notification.message }}</p>
      </div>
      <div class="notification-actions">
        <button @click="viewHistory" class="view-history-btn">查看历史记录</button>
        <button @click="closeNotification" class="close-notification-btn">关闭</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TaskNotification',
  props: {
    notification: {
      type: Object,
      default: () => ({})
    },
    show: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    showNotification() {
      return this.show && this.notification.taskId
    }
  },
  methods: {
    getStatusText(status) {
      switch (status) {
        case 'DONE': return '已完成'
        case 'FAIL': return '生成失败'
        default: return '未知'
      }
    },
    closeNotification() {
      this.$emit('close')
    },
    viewHistory() {
      this.$router.push('/history')
      this.closeNotification()
    }
  }
}
</script>

<style scoped>
.notification-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.3s ease;
}

.notification-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  animation: slideUp 0.3s ease;
}

.notification-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  position: relative;
}

.notification-icon {
  font-size: 24px;
}

.notification-header h3 {
  margin: 0;
  color: #333;
  font-size: 18px;
}

.close-btn {
  position: absolute;
  right: 0;
  top: 0;
  background: none;
  border: none;
  font-size: 24px;
  color: #999;
  cursor: pointer;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background: #f5f5f5;
  color: #666;
}

.notification-content {
  margin-bottom: 20px;
}

.notification-content p {
  margin: 8px 0;
  color: #666;
  font-size: 14px;
}

.status-badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.status-done {
  background: #e8f5e8;
  color: #2e7d32;
}

.status-fail {
  background: #ffebee;
  color: #c62828;
}

.notification-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.view-history-btn, .close-notification-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.view-history-btn {
  background: #667eea;
  color: white;
}

.view-history-btn:hover {
  background: #5a6fd8;
}

.close-notification-btn {
  background: #f5f5f5;
  color: #666;
}

.close-notification-btn:hover {
  background: #e0e0e0;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style>
